<?php

include "../init.php";
include DIR_CORE."/MySQLDB.php";

// 当前页码数
$pageNum = isset($_GET['num']) ? $_GET['num'] : 1;
// 每页显示条数
$rowsPerPage = 10;

// 接收用户搜索的关键字
$keyword = escapeString($_GET['keyword'] ? $_GET['keyword'] : '');

// 计算出总记录数
$sql = "SELECT COUNT(*) AS sum FROM publish WHERE pub_title LIKE '%$keyword%' OR pub_content LIKE '%$keyword%'";
$result = my_query($sql);
$row = mysql_fetch_assoc($result);
$rowCount = $row['sum'];

// 计算出总页数
$pages = ceil($rowCount / $rowsPerPage);

// 拼接页码字符串
include DIR_CORE."/page.php";
$strPage = page($rowCount, 3, $rowsPerPage, "./list_son.php");

// 提取 publish 表中的数据
$offset = ($pageNum - 1) * $rowsPerPage;
$sql = "SELECT * FROM publish LEFT JOIN user ON pub_owner = user_name WHERE pub_title LIKE '%$keyword%' OR pub_content LIKE '%$keyword%' ORDER BY pub_time DESC LIMIT $offset, $rowsPerPage";

$result = my_query($sql);

include DIR_VIEW."/list_son.html";

?>
